var util = require('../../utils/util.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    status: 2,
    order_info: {},
    show: false,
    express_info: [],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var that = this;
    util.postUrl('member_order/order_info', {
      order_id: options.order_id,
    }, function(res) {
      console.log(res);
      that.setData({
        order_info: res.data.datas.order_info,
        express_info: res.data.datas.order_info.express_info,
        status: res.data.datas.order_info.order_state_show.now,
        show: res.data.datas.order_info.order_state_show.show,
      })
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {


  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },
  makePhone: function() {
    var that = this;
    wx.makePhoneCall({
      phoneNumber: that.data.order_info.store_phone, //仅为示例，并非真实的电话号码
    });
  },
  cancelOrder: function() {

    var that = this;
    var item = that.data.order_info;
    var pay_sn = item.pay_sn;
    wx.showModal({
      title: '提示',
      content: '确认要取消该订单?',
      success: function(res) {
        if (res.confirm) {
          util.postUrl("member_order/order_cancel", {
            order_id: item.order_id,
          }, function(res) {
            if (res.data.code == 200) {
              util.postUrl("member_order/get_pay_info", {
                pay_sn: pay_sn,
              }, function(res) {
                console.log(res);
                wx.showToast({
                  title: '取消成功',
                })
              })

            }
          })
        }
      }
    })
  },
  quitOrder: function(e) {
    var that = this;
    var goods_id = e.currentTarget.dataset.goods_id;
    var order_info = that.data.order_info;
    order_info.goods_id = goods_id;
    wx.navigateTo({
      url: '../apply_quit/apply_quit?order=' + JSON.stringify(order_info),
    })
  },
  makePhone: function() {
    var that = this;
    wx.makePhoneCall({
      phoneNumber: that.data.express_info.driver_phone, //仅为示例，并非真实的电话号码
    })
  },
  goShopDetail: function() {
    var that = this;
    wx.navigateTo({
      url: '../shop_detail/shop_detail?store_id=' + that.data.order_info.store_id,
    })
  },
  goGoodsDetail: function(e) {
    var item = e.currentTarget.dataset.item;
    item.goods_num = item.num;
    wx.navigateTo({
      url: '../goods-details/goods-details?item=' + JSON.stringify(item),
    })
  }
})